package com.airsystem.pos.bengkel.view.report;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JTextField;

import com.airsystem.pos.bengkel.controller.MenuController;
import com.airsystem.pos.bengkel.controller.report.SparepartBillsReportController;

/**
 * @author Budi Oktaviyan <budi.oktaviyan@icloud.com>
 */
public class SparepartBillsReport extends SparepartBillsReportController {

	public SparepartBillsReport(MenuController menuController) {
		super();

		this.menuController = menuController;
		initComponents();
		load();
	}

	private void initComponents() {
		setTitle("Laporan Pesanan Sparepart");
		setFrameIcon(new ImageIcon(getClass().getResource("/images/sparepartz.png")));
		setIconifiable(true);
		setClosable(true);

		baseLayout.columnWidths = new int[] { 0 };
		baseLayout.rowHeights = new int[] { 0, 0 };
		baseLayout.columnWeights = new double[] { 1.0 };
		baseLayout.rowWeights = new double[] { 1.0, 1.0 };
		getContentPane().setLayout(baseLayout);

		panelLayout.columnWidths = new int[] { 0, 0 };
		panelLayout.rowHeights = new int[] { 0, 0 };
		panelLayout.columnWeights = new double[] { 0.0, 1.0 };
		panelLayout.rowWeights = new double[] { 0.0, 0.0 };
		basePanel.setLayout(panelLayout);

		startLabel.setFont(new Font("Verdana", 0, 12));
		startLabel.setText("Periode Awal");

		endLabel.setFont(new Font("Verdana", 0, 12));
		endLabel.setText("Periode Akhir");

		pembayaranLabel.setFont(new Font("Verdana", 0, 12));
		pembayaranLabel.setText("Metode Pembayaran");

		startChooser.setDateFormatString("d MMMM yyyy");
		((JTextField) startChooser.getDateEditor().getUiComponent()).setEditable(false);

		endChooser.setDateFormatString("d MMMM yyyy");
		((JTextField) endChooser.getDateEditor().getUiComponent()).setEditable(false);

		pembayaranCombo.setFont(new Font("Verdana", 0, 12));
		pembayaranCombo.setModel(new DefaultComboBoxModel(COMBOS));

		buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 10));

		printButton.setIcon(new ImageIcon(getClass().getResource("/images/print.png")));
		printButton.setFont(new Font("Verdana", 1, 12));
		printButton.setText("CETAK");
		buttonPanel.add(printButton);

		printButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				printButtonActionPerformed(evt);
			}
		});

		basePanel.add(startLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(30, 30, 30, 0), 0, 0));
		basePanel.add(endLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 30, 20, 0), 0, 0));
		basePanel.add(pembayaranLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 30, 20, 0), 0, 0));
		basePanel.add(startChooser, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(30, 30, 30, 30), 0, 0));
		basePanel.add(endChooser, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 30, 20, 30), 0, 0));
		basePanel.add(pembayaranCombo, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 30, 20, 30), 0, 0));

		getContentPane().add(basePanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
		getContentPane().add(buttonPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(25, 0, 0, 0), 0, 0));

		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		setBounds((screenSize.width - 500) / 2, (screenSize.height - 500) / 2, 500, 300);
	}

	private void printButtonActionPerformed(ActionEvent evt) {
		print();
	}
}